package progressBar;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.util.Log;

public class ProgressDialogBar {
    private static MyProgress myProgress = null;
    public static void show(Context ctx, String message, boolean isCancelable) {


//        if (myProgress == null) {
            myProgress = MyProgress.createDialog(ctx, message);

//        } else {
//            if (myProgress.isShowing()) {
//                myProgress.dismiss();
//            }
////            else {
//                myProgress.show();
//            }
            myProgress.show();

//        }


        // ProgressBarManager.ctx = ctx;// 防止相同的ctx重复new ProgressDialog
        // myProgress.setCancelable( isCancelable );
        // // progressBar.setProgressStyle( ProgressDialog.STYLE_SPINNER );
        // if( StringUtils.isBlank( message ) ) {
        // progressBar.setMessage( DEFAULT_MESSAGE );
        // } else {
        // progressBar.setMessage( message );
        // }
        // myProgress.setIndeterminate( false );

    }

    // 开启等待层
    public static void startProgress(Context ctx, String message,
                                     boolean isCancelable) {
        Log.d("TAG", "startProgress----------1-->");


            show(ctx, message, isCancelable);



        // tvProgress.setText(getString(msgId));
//		baseHandler.sendEmptyMessage(0);
    }

    // //开启等待层
    // public void startProgress(String msg) {
    // Log.d("TAG", "startProgress----------2-->");
    // // tvProgress.setText(msg);
    // baseHandler.sendEmptyMessage(0);
    // }
    // 关闭等待层
    public static void stopProgress() {
        Log.d("TAG", "stopProgress----------1-->");


        myProgress.dismiss();


    }

    protected static Handler baseHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case 0:
                    if (myProgress != null) {
                        myProgress.setCanceledOnTouchOutside(false);
                        myProgress.show();
                    }
                    break;
                case 1:
                    if (myProgress != null) {
                        myProgress.dismiss();
                    }
                    break;
                default:
                    break;
            }
        }

        ;
    };
}
